package database.helpers;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

public class FAQS_Table {

public databas_helper dbHelper;	
public SQLiteDatabase database;
	/**
	 * Assignment table related constants.
	 */
	public final static String FAQS_TABLE="FAQS";	
	public final static String FAQS_QSTN="QSTN";	
	public final static String FAQS_ANS="ANS";
	public final static String FAQS_ID="_id";
	
	public FAQS_Table(Context context){
		dbHelper = new databas_helper(context);
		database = dbHelper.getWritableDatabase();
	}
	public FAQS_Table(databas_helper dbHelper,SQLiteDatabase database){
		this.dbHelper = dbHelper;
		this.database = database;
	}
	
	/**\
	 * Creates a new Adminstrator
	 	 */
	public long addAdminstrator(String QSTN, String ANS){
		ContentValues values = new ContentValues();
		values.put(FAQS_QSTN,QSTN);
		values.put(FAQS_ANS,ANS);
		return database.insert(FAQS_TABLE, null, values);
	}	
	
	public void close() {
		dbHelper.close();
	}
	/**
	 * Fetch all Adminstrators
	 * @return
	 */
	public Cursor getAllAdminstrators(){
		Cursor mCursor = database.query(true, FAQS_TABLE, new String[]
				{
				FAQS_ID,FAQS_QSTN, FAQS_ANS, },null
				, null, null, null, null, null);
		if (mCursor != null) {
			mCursor.moveToFirst();
		}
		return mCursor;
	}
	/**
	 * 
	 */
	public int editAdminstrator(String QSTN,String userQSTN, String ANS, String cellnumber, String email){
		ContentValues values = new ContentValues();
		values.put(FAQS_QSTN,QSTN);
		values.put(FAQS_ANS,ANS);
		
		return database.update(FAQS_TABLE, values,FAQS_ID + "=?",new String[]{QSTN});
	}
	
	public boolean delete(String QSTN){
		return database.delete(FAQS_TABLE, FAQS_ID + "=" + QSTN, null) > 0;
	}
}
